// 双指针
var maxProfit = function(prices) {
    var minPrice = prices[0], maxProfit = 0;
    for (let i = 0; i < prices.length; i++) {
        // 最低点
        if (prices[i] < minPrice) {
            minPrice = prices[i]; // 最低点
        } else if (prices[i] - minPrice > maxProfit) { // 卖出
            maxProfit = prices[i] - minPrice;
        }
    }
    return maxProfit;
}

console.time()
console.log(maxProfit([7, 1, 5, 3, 6, 4])) 
console.timeEnd()